<?php

/* 等级 */
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\facade\Db;

class RecommendController extends AdminBaseController
{

    public function index()
    {
        
        $list = Db::name('user_say_hello')
            ->order("addtime desc")
            ->paginate(20);
        
        $page = $list->render();
        $this->assign("page", $page);
            
        $this->assign('list', $list);

        return $this->fetch();
    }


    public function add()
    {
        return $this->fetch();
    }

    public function addPost()
    {
        if ($this->request->isPost()) {
            $data      = $this->request->param();

			$content=$data['content'];
            if($content==''){
                $this->error('请填写文案内容');
            }

            $id = DB::name('user_say_hello')->insertGetId($_POST);
            if(!$id){
                $this->error("添加失败！");
            }

            $this->success("添加成功！");
        }
    }

    public function edit()
    {
        $id   = $this->request->param('id', 0, 'intval');
        
        $data=Db::name('user_say_hello')
            ->where("id={$id}")
            ->find();
        if(!$data){
            $this->error("信息错误");
        }
        
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function editPost()
    {
        if ($this->request->isPost()) {
            $data      = $this->request->param();

            $content=$data['content'];
            if($content==''){
                $this->error('请填写文案内容');
            }
            
            
            $rs = DB::name('user_say_hello')->update($data);

            if($rs === false){
                $this->error("保存失败！");
            }

            $this->success("保存成功！");
        }
    }


    public function del()
    {
        $id = $this->request->param('id', 0, 'intval');
        
        $rs = DB::name('user_say_hello')->where("id={$id}")->delete();
        if(!$rs){
            $this->error("删除失败！");
        }

        $this->success("删除成功！",url("recommend/index"));
    }



}